var app = getApp();
Page({
  data: {
    areaImg: "../images/areaThree/1.jpg",
    navData: [
      {
        text: '上户',
        index: '0-0',
      },
      {
        text: '商超',
        index: '1-0',
      },
    ],
    currentTab: 0,
    navScrollLeft: 0,
    // 接口返回的商品数组
    navList: [
      {
        tishi: '足不出户喝鲜奶，每天配送更新鲜每天配送更新鲜。足不出户喝鲜奶，每天配送更新鲜。',
        tishiImg: '../images/areaThree/shanghu.png',
        navListSata: [
          {
            index: '0-0',
            c_name: '辽宁',
            list: [
              {
                indexList: "0-0-0",
                q_name: '鞍山',
                indexListhideen: false,
                addressDetails: [
                  {
                    addressName: '辽宁科大',
                    loading: false,
                    addressIndex1: "0-0-0-0",
                  },
                ],
              },
              
            ]
          },
          {
            index: '0-1',
            c_name: '福建',
            list: [
              {
                indexList: "0-1-0",
                q_name: '深圳市2',
                indexListhideen: true,
                addressDetails: [
                  {
                    addressName: '罗湖2',
                    loading: false,
                    addressIndex1: "0-1-0-0",
                  },
                  {
                    addressName: '罗湖2',
                    loading: false,
                    addressIndex1: "0-1-0-1",
                  },
                  {
                    addressName: '罗湖2',
                    loading: false,
                    addressIndex1: "0-1-0-2",
                  },

                ],
              },
              {
                indexList: "0-1-1",
                q_name: '福州',
                indexListhideen: true,
                addressDetails: [
                  {
                    addressName: '罗湖2',
                    loading: false,
                    addressIndex1: "0-1-1-0",
                  },
                  {
                    addressName: '罗湖2',
                    loading: false,
                    addressIndex1: "0-1-1-1",
                  },
                  {
                    addressName: '罗湖2',
                    loading: false,
                    addressIndex1: "0-1-1-2",
                  },

                ],
              },
            ]
          },
          {
            index: '0-2',
            c_name: '江西',
            list: [
              {
                indexList: "0-2-0",
                q_name: '江西市3',
                indexListhideen: true,
                addressDetails: [
                  {
                    addressName: '罗湖3',
                    loading: false,
                    addressIndex1: "0-2-0-0",
                  },
                  {
                    addressName: '罗湖',
                    loading: false,
                    addressIndex1: "0-2-0-1",
                  },
                  {
                    addressName: '罗湖',
                    loading: false,
                    addressIndex1: "0-2-0-2",
                  },

                ],
              },
            ]
          },
        ]
      },
      {
        tishi: '河北地区，送奶到家周期订。',
        tishiImg: '../images/areaThree/shangchao.png',
        navListSata: [
          {
            index: '1-0',
            c_name: '河北',
            list: [
              {
                indexList: "1-0-0",
                q_name: '合肥',
                indexListhideen: false,
                addressDetails: [
                  {
                    addressName: '罗湖',
                    loading: false,
                    addressIndex1: "1-0-0-0",
                  },
                ],
              },
              {
                indexList: "1-0-1",
                q_name: '深圳市',
                indexListhideen: true,
                addressDetails: [
                  {
                    addressName: '罗湖',
                    loading: false,
                    addressIndex1: "1-0-1-0",
                  },
                  {
                    addressName: '罗湖',
                    loading: false,
                    addressIndex1: "1-0-1-1",
                  },
                  {
                    addressName: '罗湖',
                    loading: false,
                    addressIndex1: "1-0-1-2",
                  },

                ],
              },
              {
                indexList: "1-0-2",
                q_name: '深圳市',
                indexListhideen: true,
                addressDetails: [
                  {
                    addressName: '罗湖4',
                    loading: false,
                    addressIndex1: "1-0-2-0",
                  },
                  {
                    addressName: '罗湖3',
                    loading: false,
                    addressIndex1: "1-0-2-1",
                  },
                  {
                    addressName: '罗湖2',
                    loading: false,
                    addressIndex1: "1-0-2-2",
                  },

                ],
              },
            ]
          },
          {
            index: '1-1',
            c_name: '福建',
            list: [
              {
                indexList: "1-1-0",
                q_name: '深圳市2',
                indexListhideen: true,
                addressDetails: [
                  {
                    addressName: '罗湖2',
                    loading: false,
                    addressIndex1: "1-1-0-0",
                  },
                  {
                    addressName: '罗湖2',
                    loading: false,
                    addressIndex1: "1-1-0-1",
                  },
                  {
                    addressName: '罗湖2',
                    loading: false,
                    addressIndex1: "1-1-0-2",
                  },

                ],
              },
              {
                indexList: "1-1-1",
                q_name: '福州',
                indexListhideen: true,
                addressDetails: [
                  {
                    addressName: '罗湖2',
                    loading: false,
                    addressIndex1: "1-1-1-0",
                  },
                  {
                    addressName: '罗湖2',
                    loading: false,
                    addressIndex1: "1-1-1-1",
                  },
                  {
                    addressName: '罗湖2',
                    loading: false,
                    addressIndex1: "1-1-1-2",
                  },

                ],
              },
            ]
          },
          {
            index: '1-2',
            c_name: '江西',
            list: [
              {
                indexList: "1-2-0",
                q_name: '深圳市3',
                indexListhideen: true,
                addressDetails: [
                  {
                    addressName: '罗湖3',
                    loading: false,
                    addressIndex1: "1-2-0-0",
                  },
                  {
                    addressName: '罗湖',
                    loading: false,
                    addressIndex1: "1-2-0-1",
                  },
                  {
                    addressName: '罗湖',
                    loading: false,
                    addressIndex1: "1-2-0-2",
                  },

                ],
              },
            ]
          },
        ]
      }

    ],
    areaIndex: '0-0',
    areaListIndex: '0-0',

  },
  onLoad: function (e) {
    wx.getSystemInfo({
      success: (res) => {
        this.setData({
          pixelRatio: res.pixelRatio,
          windowHeight: res.windowHeight,
          windowWidth: res.windowWidth
        })
      },
    })
  },
  switchNav(event) {
    var cur = event.currentTarget.dataset.current;
    //每个tab选项宽度占1/5
    var singleNavWidth = this.data.windowWidth / 5;
    //tab选项居中                            
    this.setData({
      navScrollLeft: (cur - 2) * singleNavWidth
    })
    if (this.data.currentTab == cur) {
      return false;
    } else {
      this.setData({
        currentTab: cur
      })
    }

  },
  switchTab(event) {
    var cur = event.detail.current;
    var singleNavWidth = this.data.windowWidth / 5;
    this.setData({
      currentTab: cur,
      navScrollLeft: (cur - 2) * singleNavWidth
    });
    this.setData({
      areaIndex: cur + "-0"
    })
  },
  areaSelect(e) {
    var index = e.currentTarget.dataset.index;
    this.setData({
      areaIndex: index
    })
  },
  areaSelectList(e) {
    var navList = this.data.navList;
    var index = e.currentTarget.dataset.index;
    var addressIndex = index.split("-");
    navList[addressIndex[0]].navListSata[addressIndex[1]].list[addressIndex[2]].indexListhideen = !navList[addressIndex[0]].navListSata[addressIndex[1]].list[addressIndex[2]].indexListhideen;
    var indexListhideen
    this.setData({
      navList: navList
    })
  },
  goIndex(e) {//跳转到首页
    var navList = this.data.navList;
    var index = e.currentTarget.dataset.index;
    var addressIndex = index.split("-");
    navList[addressIndex[0]].navListSata[addressIndex[1]].list[addressIndex[2]].addressDetails[addressIndex[3]].loading = true
    this.setData({
      navList: navList
    })
    wx.switchTab({
      url: '../index/index'
    });
  },
})